﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CuaHangMayTinh.DataAccessLayer;
using CuaHangMayTinh.BusinessEntities;
using CuaHangMayTinh.Utilities;
using System.Data;

namespace CuaHangMayTinh.BusinessLogicLayer
{
    /// <summary>
    /// 
    /// </summary>
    public class BackupRestoreManager
    {
        private static BackupRestoreDA adapter = null;

        static BackupRestoreManager()
        {
            if (adapter == null)
                adapter = new BackupRestoreDA();
        }

        /// <summary>
        /// Hàm dùng để backup CSDL
        /// </summary>
        /// <param name="strFileName">tên của file .bak muốn lưu lại</param>
        /// <returns>true: Thành Công</returns>
        /// <returns>false: Thất Bại</returns>
        public static bool BackUp(string strFileName)
        {
            try
            {
                return adapter.BackUp(strFileName);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return false;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="strFileName"></param>
        /// <param name="errormessage"></param>
        /// <returns></returns>
        public static bool BackUp(string strFileName, ref string errormessage)
        {
            try
            {
                return adapter.BackUp(strFileName);
            }
            catch (Exception ex)
            {
                errormessage = ex.Message;
                Logger.Write(ex);
                return false;
            }
        }

        /// <summary>
        /// Hàm Restore CSDL
        /// </summary>
        /// <param name="strFileName">tên file muốn restore</param>
        /// <param name="user">tên đăng nhập CSDL</param>
        /// <param name="pass">password</param>
        /// <returns>true: Thành Công</returns>
        /// <returns>false: Thất Bại</returns>
        public static bool Restore(string strFileName, string user, string pass)
        {
            try
            {
                return adapter.Restore(strFileName, user, pass);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return false;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="strFileName"></param>
        /// <param name="user"></param>
        /// <param name="pass"></param>
        /// <param name="errormessage"></param>
        /// <returns></returns>
        public static bool Restore(string strFileName, string user, string pass, ref string errormessage)
        {
            try
            {
                return adapter.Restore(strFileName, user, pass);
            }
            catch (Exception ex)
            {
                errormessage = ex.Message;
                Logger.Write(ex);
                return false;
            }
        }

        /// <summary>
        /// Hàm kiểm tra trùng tên file backup
        /// </summary>
        /// <param name="strFileName"></param>
        /// <param name="BKRS"></param>
        /// <returns>True: đã có</returns>
        /// <returns>False: chưa có</returns>
        public static bool CheckName(string strFileName, bool BKRS)
        {
            try
            {
                return adapter.CheckName(strFileName, BKRS);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return false;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="strFileName"></param>
        /// <param name="BKRS"></param>
        /// <param name="errormessage"></param>
        /// <returns></returns>
        public static bool CheckName(string strFileName, bool BKRS, ref string errormessage)
        {
            try
            {
                return adapter.CheckName(strFileName, BKRS);
            }
            catch (Exception ex)
            {
                errormessage = ex.Message;
                Logger.Write(ex);
                return false;
            }
        }
    }
}
